package com.example.javamaday.leetcode;

import java.util.PriorityQueue;

public class LeetCodeTest0703 {

    PriorityQueue<Integer> priorityQueue;
    int k;

    /*  public KthLargest(int k, int[] nums) {
        this.k = k;
        priorityQueue = new PriorityQueue<Integer>();
        for (int x : nums) {
            add(x);
        }
    }  */

    public LeetCodeTest0703(int k, int[] nums) {
        this.k = k;
        priorityQueue = new PriorityQueue<Integer>();
        for (int x : nums) {
            add(x);
        }
    }

    public int add(int val) {
        priorityQueue.offer(val);
        if (priorityQueue.size() > k) {
            priorityQueue.poll();
        }
        return priorityQueue.peek();
    }


}
